import { createRouter, createWebHistory } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import HomeView from '../views/index.vue'

// 配置 NProgress
NProgress.configure({
  easing: 'ease', // 动画方式
  speed: 500, // 递增进度条的速度
  showSpinner: false, // 是否显示加载ico
  trickleSpeed: 200, // 自动递增间隔
  minimum: 0.3, // 初始化时的最小百分比
})

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'index',
      redirect:'/home',
      component: HomeView,
      children: [
        {
          path: '/home',
          name: 'home',
          component: () => import('../views/Home/index.vue'),
        },
      ]
    },

    {
      path: '/login',
      name: 'login',
      component: () => import('../views/Login/index.vue'),
    },
  ],
})

// 路由守卫中添加进度条
router.beforeEach((to, from, next) => {
  NProgress.start() // 开始进度条
  next()
})

router.afterEach(() => {
  NProgress.done() // 完成进度条
})

export default router
